<?php

/**
 * Created by PhpStorm.
 * User: dev
 * Date: 22/9/14
 * Time: 2:01 PM
 */
class Users extends Eloquent
{

    public static $table = 'users';
    public static $key = 'id';


    function __construct()
    {
        parent::__construct();

    }

    public static function isRole($roleID)
    {

        if ($roleID) {
            $loggedinRole = Users::find(Auth::user()->id)->role->id;
            if ($loggedinRole != $roleID) {
                //dd('wrong');
                return Redirect::to_route('login');
            }
        } else {
            //dd('right');
            return Redirect::to_route('login');
        }
    }

    public static function isAdmin()
    {
        if (isset(Auth::user()->role_id) && Auth::user()->role_id == 1) {
            return true;
        } else {
            return false;
        }
    }

    public static function isMember()
    {
        if (isset(Auth::user()->role_id) && Auth::user()->role_id == 2) {
            return true;
        } else {
            return false;
        }
    }

    public function role()
    {
        return $this->belongs_to('Roles');
    }

    public function post()
    {
        return $this->has_many('Post');
    }


}